//
//  Config.swift
//  GenericProjectForSwiftUI
//
//  Created by 皮蛋菌 on 2023/4/16.
//

import Foundation
import UIKit

struct Config {
    static func setup() {
        let navigationBar = UINavigationBar.appearance()
        setNavigationBar(with: navigationBar)
        
        let tabBar = UITabBar.appearance()
        setupTabBar(with: tabBar)
    }
    
    static func setNavigationBar(with navigationBar : UINavigationBar) {
        if #available(iOS 15, *) {
            let app = UINavigationBarAppearance.init()
            app.configureWithOpaqueBackground()
            app.titleTextAttributes = [
                NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18),
                NSAttributedString.Key.foregroundColor : UIColor.white
            ]
            app.backgroundColor = UIColor(red: 20/255.0, green: 158/255.0, blue: 231/255.0, alpha: 1)
//            app.shadowImage = UIColor.clear.image
            navigationBar.scrollEdgeAppearance = app
            navigationBar.standardAppearance = app
        }else{
            navigationBar.barTintColor = UIColor(red: 20/255.0, green: 158/255.0, blue: 231/255.0, alpha: 1)
            navigationBar.backgroundColor = UIColor(red: 20/255.0, green: 158/255.0, blue: 231/255.0, alpha: 1)
            navigationBar.isTranslucent = false
            navigationBar.tintColor = UIColor(red: 20/255.0, green: 158/255.0, blue: 231/255.0, alpha: 1)
            navigationBar.titleTextAttributes = [
                NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18),
                NSAttributedString.Key.foregroundColor : UIColor.white
            ]
        }
    }
    
    static func setupTabBar(with tabBar : UITabBar) {
        if #available(iOS 15, *) {
            let color = UIColor.white
            let tabBarAppearance = UITabBarAppearance()
            tabBarAppearance.backgroundColor = color
            //未选中颜色
            tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor : UIColor.gray
            ]
            //选中颜色
            tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor : UIColor.init(red: 31/255, green: 185/255, blue: 34/255, alpha: 1)
            ]
            tabBar.standardAppearance = tabBarAppearance
            tabBar.scrollEdgeAppearance = tabBarAppearance
        }else{
            //未选中颜色
            tabBar.unselectedItemTintColor = UIColor.gray
            //选中颜色
            tabBar.tintColor = UIColor.init(red: 31/255, green: 185/255, blue: 34/255, alpha: 1)
        }
    }
}
